/**
 * Copyright (c) Software Institude of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.modeler.model.uml.BasicActivities;
// imports:
import org.w3c.dom.Element;

import edu.pku.sei.gefcommon.descriptor.annotation.MethodProperty;
import edu.pku.sei.modeler.model.common.*;
import edu.pku.sei.modeler.model.core.*;
import edu.pku.sei.modeler.model.xml.XMLUtility;

import edu.pku.sei.modeler.model.uml.CompleteActivities.ObjectNodeOrderingKind;
import edu.pku.sei.modeler.model.uml.Kernel.ValueSpecification;
import edu.pku.sei.modeler.model.uml.BasicBehaviors.Behavior;
import edu.pku.sei.modeler.model.uml.BehaviorStateMachines.State;
import edu.pku.sei.modeler.model.uml.Kernel.Type;

import edu.pku.sei.modeler.model.uml.FundamentalActivities.ActivityNode;
import edu.pku.sei.modeler.uml.modelHelper.ModelPackage;

/**
 * @generated
 *
 */
public class ObjectNode extends ActivityNode implements IObjectNode {
	// attributes
	
	protected ObjectNodeOrderingKind ordering;
	
	protected boolean isControlType;
	
	protected ValueSpecification upperBound;
	
	
	
	
	// references
	
	protected MetaTypedList selection;
	
	protected MetaTypedList inState;
	
	protected MetaTypedList type;
	
	public ObjectNode(){
		this.name = "unnamed objectnode";
	}
	
	// getters & setters for attributes
	
	public ObjectNodeOrderingKind getOrdering() {
		return ordering;
	}
	public void setOrdering(ObjectNodeOrderingKind newOrdering) {
		ObjectNodeOrderingKind oldordering = ordering;
		ordering = newOrdering;
		firePropertyChange(ModelPackage.OBJECTNODE_ORDERING, oldordering, newOrdering);
	}
	
	@MethodProperty(
			id = "OBJECTNODE_ISCONTROLTYPE",
			catalog = "Model",
			name = ModelPackage.OBJECTNODE_ISCONTROLTYPE,
			setter = "setisControlType"
			)
	
	public boolean getIsControlType() {
		return isControlType;
	}
	public void setIsControlType(boolean newIsControlType) {
		boolean oldisControlType = isControlType;
		isControlType = newIsControlType;
		firePropertyChange(ModelPackage.OBJECTNODE_ISCONTROLTYPE, oldisControlType, newIsControlType);
	}
	
	public ValueSpecification getUpperBound() {
		return upperBound;
	}
	public void setUpperBound(ValueSpecification newUpperBound) {
		ValueSpecification oldupperBound = upperBound;
		upperBound = newUpperBound;
		firePropertyChange(ModelPackage.OBJECTNODE_UPPERBOUND, oldupperBound, newUpperBound);
	}
	
	// getters for references
	
	public MetaTypedList getSelection() {
		if(selection == null) {
			selection = new MetaTypedList(Behavior.class, this, ModelPackage.OBJECTNODE_SELECTION);
		}
		return selection;
	}
	
	public MetaTypedList getInState() {
		if(inState == null) {
			inState = new MetaTypedList(State.class, this, ModelPackage.OBJECTNODE_INSTATE);
		}
		return inState;
	}
	
	public MetaTypedList getType() {
		if(type == null) {
			type = new MetaTypedList(Type.class, this, ModelPackage.TYPEDELEMENT_TYPE);
		}
		return type;
	}
	
	// save & load
	public void serialize(Element root) {
		super.serialize(root);
		// attributes
		
		XMLUtility.xmlInstance.serializeNode(root, ModelPackage.OBJECTNODE_ORDERING, ordering);
		
		XMLUtility.xmlInstance.serializeAttribute(root, ModelPackage.OBJECTNODE_ISCONTROLTYPE, isControlType);
		
		XMLUtility.xmlInstance.serializeNode(root, ModelPackage.OBJECTNODE_UPPERBOUND, upperBound);
		
		// references
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.OBJECTNODE_SELECTION, selection);		
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.OBJECTNODE_INSTATE, inState);		
		
		XMLUtility.xmlInstance.serializeNodesNotContain(root, ModelPackage.TYPEDELEMENT_TYPE, type);		
		
	}
	
	public void deSerialize(Element root) {
		super.deSerialize(root);
		// attributes
		
		ordering = (ObjectNodeOrderingKind)XMLUtility.xmlInstance.deSerializeNode(root, ModelPackage.OBJECTNODE_ORDERING, this);
		
		isControlType = XMLUtility.xmlInstance.deSerializeBoolean(root, ModelPackage.OBJECTNODE_ISCONTROLTYPE);
		
		upperBound = (ValueSpecification)XMLUtility.xmlInstance.deSerializeNode(root, ModelPackage.OBJECTNODE_UPPERBOUND, this);
		
		// references
		
		this.getSelection().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.OBJECTNODE_SELECTION, this));
		
		this.getInState().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.OBJECTNODE_INSTATE, this));
		
		this.getType().addAll(XMLUtility.xmlInstance.deSerializeNodesNotContain(root, ModelPackage.TYPEDELEMENT_TYPE, this));
		
	}
	
	public void dynamicSet(String featureID, Object value) {
		if(featureID == null || "".equals(featureID)) {
			return;
		}
		// attributes
		
		else if(ModelPackage.OBJECTNODE_ORDERING.equals(featureID)) {
			ordering = (ObjectNodeOrderingKind)value;
		}
		
		else if(ModelPackage.OBJECTNODE_UPPERBOUND.equals(featureID)) {
			upperBound = (ValueSpecification)value;
		}
		
		// references
		
		else if(ModelPackage.OBJECTNODE_SELECTION.equals(featureID)) {
			getSelection().add(value);
		}
		
		else if(ModelPackage.OBJECTNODE_INSTATE.equals(featureID)) {
			getInState().add(value);
		}
		
		else if(ModelPackage.TYPEDELEMENT_TYPE.equals(featureID)) {
			getType().add(value);
		}
		
		else
			super.dynamicSet(featureID, value);
	}
}
 
 
 
 
 